package com.xh.bussiness.tms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xh.bussiness.system.bean.dto.StudentDto;
import com.xh.bussiness.tms.dao.ClassStudentMapper;
import com.xh.bussiness.tms.model.ClassStudent;
import com.xh.bussiness.tms.service.IClassStudentService;
import com.xh.core.service.impl.BaseServiceImpl;
import com.xh.core.util.CacheUtils;
import com.xh.core.util.StringUtils;
import com.xh.core.util.UserUtils;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ClassStudentServiceImpl extends BaseServiceImpl<ClassStudentMapper, ClassStudent> implements IClassStudentService {


    /**
     * deleteStudentOrClassByClassIdOrStuId
     *   1.  stuId   classId    删除该班级的学生
     *   2.  stuId              删除学生报名的所有班级
     *   3.  classId            删除班级里的所有学生
     *
     */
    @Override
    public void deleteStudentOrClassByClassIdOrStuId(ClassStudent bean) {
        QueryWrapper<ClassStudent> qw = new QueryWrapper<>();
        if(!StringUtils.isEmpty(bean.getClassId())){
            qw.eq("class_id",bean.getClassId());
        }

        if(!StringUtils.isEmpty(bean.getStudentId())){
            qw.eq("student_id",bean.getStudentId());
        }
        super.deleteByCondition(qw);
//        List<ClassStudent> classStudents = super.queryByCondition(qw);
//
//        for(ClassStudent cs : classStudents){
//            super.delete(cs.getId());
//        }
    }

    @Override
    public List<ClassStudent> getClassStudentDataByStuIdAndClassId(ClassStudent bean) {
        QueryWrapper<ClassStudent> qw = new QueryWrapper<>();
        if(!StringUtils.isEmpty(bean.getClassId())){
            qw.eq("class_id",bean.getClassId());
        }

        if(!StringUtils.isEmpty(bean.getStudentId())){
            qw.eq("student_id",bean.getStudentId());
        }

        return super.queryByCondition(qw);
    }

    @Override
    public List<StudentDto> queryStudentByClassId(String classId) {
        return this.dao.queryStudentByClassId(classId);
    }
}
